<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Productos</title>
</head>
<body>
<table cellpadding="5" cellspacing="0" border="0" width="60%">
	<tr>
		<c:if test="${not empty mensaje}">
		<td colspan="3" style="border:1px; border-color:red;">
			<div style="width:800px; color:red; background-color:#E7EAEF; font-weight: bold;">
				&nbsp;&nbsp;&nbsp;${mensaje}
			</div>
		</td>
		</c:if>
	</tr>
	<tr>
		<td bgcolor="#e7eaef" width="200px" valign="top">
		<table>
			<tr><td height="100px"><img src="img/icono-ofertas.gif" /></td></tr>

<c:forEach var="producto" items="${listaProductosOfertados}" >  
	 		<tr>
	      	  <td width="390">
	      	  <form:form name="form_o_${producto.idProducto}" method="POST" commandName="producto" action="addShopping.do">
	          <table width="200" border="0">
	  			<tr>
	    			<td width="90" rowspan="4">
	    				<input type="hidden" name="idProducto" value="${producto.idProducto}" />
	    				<img src="img/products/${producto.idProducto}.jpg" alt="" width="90" height="90" />
	    			</td>
	    			<td width="100" align="left"><b>${producto.nombre}</b></td>
	  			</tr>
	  			<tr>
	    			<td align="left"><label>S/.</label> ${producto.precio}</td>
	  			</tr>
	  			<tr>
	    			<td align="left"><input type="text" name="txtCantidad" id="txtCantidad" size="10" /></td>
	  			</tr>
	 			<tr>
	    			<td height="26" align="left">
	    				<a href="#" onclick="javascript:document.form_o_${producto.idProducto}.submit();">
	    					<img src="img/shopping/comprar.gif" alt="" width="60" height="20" />
	    				</a>
	    			</td>
	  			</tr>
	  			<tr>
	    			<td height="26">&nbsp;</td>
	  			</tr>
			  </table>
			  </form:form>
	          </td>
	    	</tr>
</c:forEach>

	</table>
	</td>
	<td width="40px"></td>
	<td valign="top">  
	<table>   
  		<tr>
  		<td colspan="2" align="left" style="font-family: sans-serif; font-size: small; font-weight: bold;">
			<a href="${pageContext.request.contextPath}/shopping.do"><img src="img/shopping/AgregarCarrito.gif" alt="" width="190" height="29" /></a>
			<br><label>&nbsp;&nbsp;&nbsp;Productos:&nbsp;</label><c:if test="${pedido == null}">0</c:if>${pedido.cantProductos} 
		</td>
		</tr>
		<tr>
			<td colspan="2" style="border: thin;" align="right">
			    productos encontrados:&nbsp;<b>${fn:length(listaProductos)}</b>
			    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			    <c:set var="paginglinkant" value="${pageContext.request.contextPath}/getProducts.do?beginpage=${beginpage-6}&endpage=${endpage-6}" />
			    <c:set var="paginglinksig" value="${pageContext.request.contextPath}/getProducts.do?beginpage=${beginpage+6}&endpage=${endpage+6}" />
			    <c:if test="${idCategoria != null}">
			    	<c:set var="paginglinkant" value="${paginglinkant}&idCategoria=${idCategoria}" />
			    	<c:set var="paginglinksig" value="${paginglinksig}&idCategoria=${idCategoria}" />
			    </c:if>
			    <c:choose>
			    <c:when test="${beginpage != 1}">
					<a href="${paginglinkant}">
						<span style="color: blue;">
						<img alt="Anteriores 6" src="img/Left.gif" width="16px" height="16px" align="middle"/>anterior
						</span>
					</a>
				</c:when>
				<c:otherwise>
					<img alt="Anteriores 6" src="img/Left.gif" width="16px" height="16px" align="middle"/>anterior
				</c:otherwise>
				</c:choose>
				&nbsp;&nbsp;<b>${beginpage}</b> a <b>${endpage}</b>&nbsp;&nbsp;
				<c:choose>
				<c:when test="${endpage < fn:length(listaProductos)}">
					<a href="${paginglinksig}">
						<span style="color: blue;">
						siguiente<img alt="Siguientes 6" src="img/Right.gif" width="16px" height="16px" align="middle"/>
						</span>
					</a>
				</c:when>
				<c:otherwise>
					siguiente<img alt="Siguientes 6" src="img/Right.gif" width="16px" height="16px" align="middle"/>
				</c:otherwise>
				</c:choose>
				<br/><br/>
			</td>
  		</tr>
<c:set var="cont" value="0" />
<c:forEach var="prod" items="${listaProductos}" begin="${beginpage}" end="${endpage}" >
	  <c:if test="${cont%2==0}">
	    <tr> 
      	<td width="390">
      	  <form:form name="form_p_${prod.idProducto}" method="POST" commandName="prod" action="addShopping.do">
          <table width="200" border="0">
  			<tr>
    			<td width="90" rowspan="4">
    				<input type="hidden" name="idProducto" value="${prod.idProducto}" />
    				<img src="img/products/${prod.idProducto}.jpg" alt="" width="90" height="90" />
    			</td>
    			<td width="100" align="left">${prod.nombre}</td>
  			</tr>
  			<tr>
    			<td align="left"><label>S/.</label> ${prod.precio}</td>
  			</tr>
  			<tr>
    			<td align="left"><input type="text" name="txtCantidad" id="txtCantidad" size="10" /></td>
  			</tr>
 			<tr>
    			<td height="26" align="left">
    				<a href="#" onclick="javascript:document.form_p_${prod.idProducto}.submit();">
    					<img src="img/shopping/comprar.gif" alt="" width="60" height="20" />
    				</a>
    			</td>
  			</tr>
  			<tr>
    			<td height="26">&nbsp;</td>
  			</tr>
		   </table>
		   </form:form>
      	</td>
      </c:if>
      <c:if test="${cont%2!=0}">
  		<td width="380">
  		  <form:form name="form_p_${prod.idProducto}" method="POST" commandName="prod" action="addShopping.do">
          <table width="200" border="0">
  			<tr>
    			<td width="90" rowspan="4">
    				<input type="hidden" name="idProducto" value="${prod.idProducto}" />
    				<img src="img/products/${prod.idProducto}.jpg" alt="" width="90" height="90" />
    			</td>
    			<td width="100" align="left">${prod.nombre}</td>
  			</tr>
  			<tr>
    			<td align="left"><label>S/.</label> ${prod.precio}</td>
  			</tr>
  			<tr>
    			<td align="left"><input type="text" name="txtCantidad" id="txtCantidad" size="10" /></td>
  			</tr>
  			<tr>
    			<td height="26" align="left">
    				<a href="#" onclick="javascript:document.form_p_${prod.idProducto}.submit();">
    					<img src="img/shopping/comprar.gif" alt="" width="60" height="20" />
    				</a>
    			</td>
  			</tr>
  			<tr>
    			<td height="26">&nbsp;</td>
  			</tr>
		</table>
		</form:form>
        </td>
      </tr>
      </c:if>
      <c:set var="cont" value="${cont+1}" />
</c:forEach>
</table>
</td>
</tr>
</table>
</body>
</html>